//
//  AlertShareView.m
//  CYWFrame
//
//  Created by Macx on 2017/12/7.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "AlertShareView.h"

#import "UIView+LZCView.h"
#import "Share.h"
#import "LCButton.h"

@interface AlertShareView ()

@property (nonatomic, strong) UIView *alertview;
@property (nonatomic, assign) BOOL judge;

@property (nonatomic, strong) NSDictionary *param;

@end

@implementation AlertShareView {
    CGFloat seleW;
    CGFloat seleW2;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //创建遮罩
        UIView *mask = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        [self addSubview:mask];
        mask.backgroundColor = [UIColor blackColor];
        mask.alpha = 0.3f;
        [mask addTarget:self action:@selector(maskClick)];
        
        //创建alert
        self.alertview = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SW(3))];
        self.alertview.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:0.5];
        [self addSubview:_alertview];
        [self exChangeOut:self.alertview dur:0.2];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 第二次就不需要重新创建
    if (self.judge == 0) {
        
        
        NSArray *imgArr = @[@"share_wechat", @"share_pyq", @"share_qq", @"share_zone", @"share_weibo"];
        NSArray *textArr = @[@"微信", @"朋友圈", @"QQ", @"QQ空间", @"微博"];
        
        for (int i = 0; i < imgArr.count; i++) {
            CGFloat btnX = 0.0f;
            LCButton *indexBtn;
            btnX = SW(5)*i;
            indexBtn = [[LCButton alloc] initWithFrame:CGRectMake(btnX, SW(20), SW(5), SW(5))];
            [indexBtn setTitle:textArr[i] forState:UIControlStateNormal];
            [indexBtn setTitleColor:kGrayColor forState:UIControlStateNormal];
            [indexBtn setImage:IMAGE(imgArr[i]) forState:UIControlStateNormal];
            indexBtn.tag = 1000+i;
            [indexBtn addTarget:self action:@selector(lbBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            
            [_alertview addSubview:indexBtn];
        }
    }
    self.judge = YES;
    
}

- (void)lbBtnClick:(LCButton *)btn {
    
    if (btn.tag == 1000) {
        [Share shareActionwx:self.param];
    }
    else if (btn.tag == 1001) {
        [Share shareActionpyq:self.param];
    }
    else if (btn.tag == 1002) {
        [Share shareActionqq:self.param];
    }
    else if (btn.tag == 1003) {
        [Share shareActionqqZone:self.param];
    }
    else if (btn.tag == 1004) {
        [Share shareActionwb:self.param];
    }
    
}


#pragma mark ==========响应方法==========
// 弹出
-(void)exChangeOut:(UIView *)changeOutView dur:(CFTimeInterval)dur{
    
    [UIView animateWithDuration:0.5 animations:^{
        _alertview.frame = CGRectMake(0,SCREEN_HEIGHT-SW(3), SCREEN_WIDTH, SW(3));
    }];
}
- (void)maskClick
{
    // 取消弹框
    [UIView animateWithDuration:0.2 animations:^{
        _alertview.frame = CGRectMake(0,SCREEN_HEIGHT, SCREEN_WIDTH, SW(3));
        self.alpha = 0.0;
    } completion:^(BOOL finished) {
        self.alertview = nil;
        [self removeFromSuperview];
    }];
}

- (void)initShow:(NSDictionary *)param {
    self.param = param;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
